package com.erp.erp_ui.ProductFjGysBak;

import com.erp.erp_entitys.ProductFjGysBak.ProductFjGysBakEntity;
import com.erp.erp_entitys.ProductFjGysBak.ProductFjGysBakExample;
import com.erp.erp_servers.ProductFjGysBak.IProductFjGysBakService;
import com.erp.erp_ui.base.Base;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OperationLogControl
 * @Description 产品附件备选 供应商信息
 * @Author songjizhen
 * @Date 2020-06-30 21:41
 * @Version 1.0
 */
@Controller
@RequestMapping(value = "productfjgysbak")
public class ProductFjGysBakControl extends Base {

    @Autowired
    IProductFjGysBakService productFjGysBakService;
    /**
     * 根据产编码、规格编码获取信息
     * @param
     * @return
     */
    @RequestMapping(value = "selectByPage")
    @ResponseBody
    public R<List<ProductFjGysBakEntity>> selectByPage(String productCode, String fjCode){
        try{
            ProductFjGysBakExample example=new ProductFjGysBakExample();
            ProductFjGysBakExample.Criteria criteria = example.createCriteria();
            criteria.andProductCodeEqualTo(productCode);
            criteria.andFjCodeEqualTo(fjCode);
            List<ProductFjGysBakEntity> productFjGysBakEntities = productFjGysBakService.selectByExample(example);
            return R.build(productFjGysBakEntities);
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 批量删除备选 供应商
     * @param ids
     * @return
     */
    @RequestMapping(value = "delgys",method = RequestMethod.POST)
    @ResponseBody
    public R<Integer> delgys(String[] ids){
        try{
            List<Integer> list=new ArrayList<>();
            for(int i=0;i<ids.length;i++){
                list.add(Integer.parseInt(ids[i].replace("[","").replace("]","")));
            }
            ProductFjGysBakExample example=new ProductFjGysBakExample();
            ProductFjGysBakExample.Criteria criteria = example.createCriteria();
            criteria.andIdIn(list);
            int num = productFjGysBakService.deleteByExample(example);
            return R.build(num);
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 保存
     * @param pfgb
     * @return
     */
    @RequestMapping(value = "savegys",method = RequestMethod.POST)
    @ResponseBody
    public R<Integer> savegys(@RequestBody ProductFjGysBakEntity pfgb){
        try{
            int num=0;
            if(pfgb.getId() ==null){
               num= productFjGysBakService.insertSelective(pfgb);
            }else{
                num=productFjGysBakService.updateByPrimaryKeySelective(pfgb);
            }
            return R.build(num);
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }
}
